﻿@page "/system_manager/resource"
@inherits TreeTableBase<ResourceDto, Guid, ResourceEdit>
<div>
    <Table TItem="ResourceDto"
           DataSource="@_dtos"
           OnChange="@onChange"
           Loading="@_tableIsLoading"
           TreeChildren="item=>item.Children"
           @bind-SelectedRows="_selectedRows"
           HidePagination="true"
           IndentSize="25"
           Context="model">
        <TitleTemplate>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="system_manager_resource_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnClickDeletes">
                            @localizer["删除选中"]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="system_manager_resource_add">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnClickAdd">
                                    @localizer["添加"]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="system_manager_resource_refresh">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="reload" OnClick="OnReLoadTable">
                                    @localizer["刷新"]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="system_manager_resource_download_seed_data">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="download" OnClick="OnDownloadClick">
                                    @localizer["种子数据"]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <RowTemplate>
            <Selection CheckStrictly Width="5%" />
            <Column @bind-Field="@model.Name" Width="20%">
                <span>
                    @if (!string.IsNullOrEmpty(model.Icon))
                    {
                        <Icon Type="@model.Icon"></Icon>
                    }@model.Name
                </span>
            </Column>

            @*<Column @bind-Field="@model.Key" Width="10%" />
            <Column @bind-Field="@model.Path" Width="10%"/>*@
            <Column @bind-Field="@model.Type" Width="5%">
                <TagRandomColor Text="@(EnumHelper.GetEnumDescription(model.Type))"></TagRandomColor>
            </Column>
            <Column @bind-Field="@model.Order" Width="5%" />
            <Column @bind-Field="@model.IsLocked" Width="10%">
                <ResourceAuthorize ResourceKey="system_manager_resource_lock">
                    <Authorized>
                        <Switch @bind-Value="@model.IsLocked" OnChange="e=>OnChangeIsLocked(model,e)"></Switch>
                    </Authorized>
                    <NotAuthorized>
                        <TagYesNo Yes="model.IsLocked"></TagYesNo>
                    </NotAuthorized>
                </ResourceAuthorize>
            </Column>
            <Column @bind-Field="@model.CreatedTime" Width="10%" Format="@ClientConstant.DateTimeFormat" />
            @*<Column @bind-Field="@model.Remark" />*@
            <ActionColumn Width="10%">
                <Space>
                    <ResourceAuthorize ResourceKey="system_manager_resource_add_children">
                        <SpaceItem>
                            <Tooltip Title="@(localizer["添加子项"])" ArrowPointAtCenter="true">
                                <Button Icon="subnode" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickAddChildren(model)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    @if (!model.Type.Equals(ResourceType.Root))
                    {
                        <ResourceAuthorize ResourceKey="system_manager_resource_edit">
                            <SpaceItem>
                                <Tooltip Title="@(localizer["编辑"])" ArrowPointAtCenter="true">
                                    <Button Icon="edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickEdit(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        </ResourceAuthorize>

                        <ResourceAuthorize ResourceKey="system_manager_resource_show_function">
                            <SpaceItem>
                                <Tooltip Title="@(localizer["绑定接口"])" ArrowPointAtCenter="true">
                                    <Button Icon="api" Type="@ButtonType.Primary" OnClick="()=>OnShowFunctionClick(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        </ResourceAuthorize>

                        <ResourceAuthorize ResourceKey="system_manager_resource_detail">
                            <SpaceItem>
                                <Tooltip Title="@(localizer["详情"])" ArrowPointAtCenter="true">
                                    <Button Icon="eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        </ResourceAuthorize>

                        <ResourceAuthorize ResourceKey="system_manager_resource_delete">
                            <SpaceItem>
                                <Tooltip Title="@(localizer["删除(包含子项)"])" ArrowPointAtCenter="true">
                                    <Button Icon="delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        </ResourceAuthorize>
                    }else{
                     <ResourceAuthorize ResourceKey="system_manager_resource_detail">
                            <SpaceItem>
                                <Tooltip Title="@(localizer["详情"])" ArrowPointAtCenter="true">
                                    <Button Icon="eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        </ResourceAuthorize>
                    }
                </Space>
            </ActionColumn>
        </RowTemplate>
    </Table>
</div>

